// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   change_delete_details.java

package finance.voucher;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class change_delete_details extends HttpServlet
{

	public change_delete_details()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 finance_db = new nseer_db_backup1(dbApplication);
		try
		{
			if (finance_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String id = request.getParameter("id");
				String voucher_id = request.getParameter("voucher_id");
				String debit_subtotal = request.getParameter("debit_subtotal");
				String loan_subtotal = request.getParameter("loan_subtotal");
				String sql = (new StringBuilder("delete from finance_voucher_details where id='")).append(id).append("'").toString();
				finance_db.executeUpdate(sql);
				String sql2 = (new StringBuilder("select * from finance_voucher where id='")).append(voucher_id).append("'").toString();
				ResultSet rs2 = finance_db.executeQuery(sql2);
				if (rs2.next())
				{
					double debit_sum = rs2.getDouble("debit_sum") - Double.parseDouble(debit_subtotal);
					double loan_sum = rs2.getDouble("loan_sum") - Double.parseDouble(loan_subtotal);
					String sql1 = (new StringBuilder("update finance_voucher set debit_sum='")).append(debit_sum).append("',loan_sum='").append(loan_sum).append("',check_tag='0',change_tag='1' where id='").append(voucher_id).append("'").toString();
					finance_db.executeUpdate(sql1);
				}
				finance_db.commit();
				finance_db.close();
				response.sendRedirect((new StringBuilder("finance/voucher/change.jsp?id=")).append(voucher_id).toString());
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
